package dialogos;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import accesoADatos.AccesoADatos;
import datos.Profesional;
import datos.Turno;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public abstract class ReservaDialog extends javax.swing.JDialog {

	private static final long serialVersionUID = 1L;
	private JLabel jCliente;
	protected JComboBox jComboCliente;
	protected JButton jButton1;
	private JLabel lHora;
	protected Component hora;
	protected JButton jBCancelar;
	protected JButton jBAceptar;
	protected Profesional p;
	protected Turno t;
	protected Hashtable hash = new Hashtable();
	protected JLabel lTexto;
	private JLabel lProfesional;
	protected JComboBox jComboBox1;
	private JLabel lTipoServicio;
	protected SimpleDateFormat formateador = new SimpleDateFormat("dd 'de' MMMM");

	public static void main(String[] args) {
	}
	public ReservaDialog(JDialog dialogo, Turno t2,	Profesional p2) {
			super(dialogo,true);
			this.p=p2;
			this.t=t2;
			initGUI();
			}
	
	/**
	 * @wbp.parser.constructor
	 */
	protected ReservaDialog(JFrame frame,Turno t,Profesional p) {
		super(frame,true);
		this.p=p;
		this.t=t;
		initGUI();
	}
	
	private void initGUI() {
		try {
			FlowLayout thisLayout = new FlowLayout();
			thisLayout.setHgap(10);
			thisLayout.setVgap(10);
			getContentPane().setLayout(thisLayout);
			this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			{
				lTexto = new JLabel();
				getContentPane().add(lTexto);
				lTexto.setText("Desea confirmar el turno con el profesional");
				lTexto.setFont(new java.awt.Font("Dialog",1,12));
				lTexto.setPreferredSize(new java.awt.Dimension(300, 20));
				lTexto.setHorizontalAlignment(SwingConstants.CENTER);
				lTexto.setForeground(new java.awt.Color(0,0,0));
				lTexto.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lProfesional = new JLabel();
				lProfesional.setText(this.p.toString());
				getContentPane().add(lProfesional);
				lProfesional.setPreferredSize(new java.awt.Dimension(300, 20));
				lProfesional.setHorizontalAlignment(SwingConstants.CENTER);
				lProfesional.setForeground(new java.awt.Color(0,0,0));
				lProfesional.setFont(new java.awt.Font("Tahoma",1,12));
				lProfesional.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lHora = new JLabel();
				getContentPane().add(lHora);
				lHora.setText("Fecha y Hora");
				lHora.setPreferredSize(new java.awt.Dimension(144, 20));
				lHora.setHorizontalAlignment(SwingConstants.CENTER);
				lHora.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lHora.setForeground(new java.awt.Color(0,0,0));
			}
			{
				this.initFechaComponent();
				this.hora.setFont(new Font("Dialog", Font.BOLD, 12));
			}
			{
				jCliente = new JLabel();
				getContentPane().add(jCliente);
				jCliente.setText("Cliente");
				jCliente.setPreferredSize(new java.awt.Dimension(144, 20));
				jCliente.setHorizontalAlignment(SwingConstants.CENTER);
				jCliente.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				jCliente.setForeground(new java.awt.Color(0,0,0));
			}
			{
				List l=AccesoADatos.getInstance().getClientes();
				ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(l.toArray());
				for (int i=0; i<l.size(); i++)
					hash.put(l.get(i).toString(),l.get(i));
				jComboCliente = new JComboBox();
				getContentPane().add(jComboCliente);
				jComboCliente.setModel(jComboBox1Model);
				jComboCliente.setPreferredSize(new java.awt.Dimension(180, 20));
				jComboCliente.setBackground(new java.awt.Color(255,255,255));
				jComboCliente.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				jComboCliente.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
					}
				});
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Nuevo");
				jButton1.setPreferredSize(new java.awt.Dimension(80, 21));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ClienteDialogo c = new ClienteDialogo(ReservaDialog.this);
						if(c.getOpcion() == true){
							String cliente = c.getCliente().toString();
							actualizarClientes();
							jComboCliente.getModel().setSelectedItem(cliente);
						}
					}
				});
			}
			{
				lTipoServicio = new JLabel();
				getContentPane().add(lTipoServicio);
				lTipoServicio.setText("Tipo de Servicio");
				lTipoServicio.setPreferredSize(new java.awt.Dimension(144, 20));
				lTipoServicio.setHorizontalAlignment(SwingConstants.CENTER);
				lTipoServicio.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lTipoServicio.setForeground(new java.awt.Color(0,0,0));
			}
			{
				ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "Corte", "Color" });
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				jComboBox1.setModel(jComboBox1Model);
				jComboBox1.setPreferredSize(new java.awt.Dimension(180, 20));
				jComboBox1.setBackground(new java.awt.Color(255,255,255));
				jComboBox1.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				jComboBox1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jComboBox1ActionPerformed(evt);
					}
				});
			}
			{
				jBAceptar = new JButton();
				getContentPane().add(jBAceptar);
				jBAceptar.setText("Aceptar");
				jBAceptar.setPreferredSize(new java.awt.Dimension(120, 25));
				jBAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jBAceptarActionPerformed(evt);
					}
				});
			}
			{
				jBCancelar = new JButton();
				getContentPane().add(jBCancelar);
				jBCancelar.setText("Cancelar");
				jBCancelar.setPreferredSize(new java.awt.Dimension(120, 25));
				jBCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ReservaDialog.this.dispose();
					}
				});
			}
			pack();
			this.setSize(450, 245);
			this.setResizable(false);
			this.setLocationRelativeTo(null);
			this.getContentPane().setBackground(new Color(220,220,220));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected abstract void jBAceptarActionPerformed(ActionEvent evt); {
		/*Reserva r=new Reserva();
		r.setCliente((Cliente)this.hash.get(jComboCliente.getSelectedItem().toString()));
		r.setProfesional(p);
		r.setTurno(t);
		r.setTipo("Comun");
		r.setTipoServicio((String)this.jComboBox1.getSelectedItem());
		//AccesoADatos.getInstance().setTurno(t);
		AccesoADatos.getInstance().setReserva(r);
		JOptionPane.showMessageDialog(this,"El turno del dia " + formateador.format(t.getFecha()) + " con el profesional " + p.toString() + " ha sido confirmado." , "Turno Confirmado", JOptionPane.INFORMATION_MESSAGE);
		this.dispose();*/
	}
	
	protected abstract void initFechaComponent();
	
	protected void jComboBox1ActionPerformed(ActionEvent evt) {
		((JFormattedTextField)ReservaDialog.this.hora).setValue(t.getFecha());
	}
	
	private void actualizarClientes(){
		this.jComboCliente.removeAllItems();
		List l = AccesoADatos.getInstance().getClientes();
		for (int i=0; i<l.size(); i++){
			hash.put(l.get(i).toString(),l.get(i));
			this.jComboCliente.addItem(l.get(i));
		}
	}

}
